//
//  NSString+Extension.m
//  GameSDK
//
//  Created by Johnny on 2017/7/31.
//  Copyright © 2017年 Johnny. All rights reserved.
//

#import "NSString+Extension.h"
#import <UIKit/UIKit.h>
#import "GSDKCommonMethod.h"
@implementation NSString (Extension)
- (BOOL)isEmpty {
    if (self == nil) {
        return NO;
    } else {
        if (self.length == 0) {
            return NO;
        }
    }
    return YES;
}

+ (NSString *)getRandomPassword:(int)num {
    NSArray * array = @[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",
                        @"i",@"j",@"k",@"l",@"m" ,@"n",@"o",@"p",@"q",
                        @"r",@"s",@"t",@"u",@"v",@"w",@"s",@"y",@"z",
                        @"0",@"1",@"2",@"3",@"4",@"5",@"6",@"7",
                        @"8",@"9",@"_"];
    long int pwdLength = [array count];
    int count = 0;
    NSMutableString * pwdString = [[NSMutableString alloc]init];
    while (count < pwdLength && count <num) {
        int value = (arc4random() % pwdLength) + 0;
        if (value < pwdLength) {
            [pwdString appendString:array[value]];
            count++;
        }
    }
    return (NSString *)pwdString;
}

+ (NSString *)getLanguage {
    NSString *language = @"";
    switch (GSDKCOMMONMETHOD.language) {
        case GSDK_LANGUAGE_EN:
            language = @"en";
            break;
        case GSDK_LANGUAGE_CN_HANS:
            language = @"zh-Hans";
            break;
    }
    return language;
}

+ (NSString *)localizedStringForKey:(NSString *)key value:(NSString *)value {
    static NSBundle *bundle = nil;
    if (bundle == nil) {
        bundle = [NSBundle bundleWithPath:[[NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"ZYSDK_Resourcres" ofType:@"bundle"]] pathForResource:[NSString stringWithFormat:@"lan/%@", [NSString getLanguage]] ofType:@"lproj"]];
    }
    value = [bundle localizedStringForKey:key value:value table:nil];
    return [[NSBundle mainBundle] localizedStringForKey:key value:value table:nil];
}



@end
